package com.ruoyi.web.controller.persona;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.FansInfo;
import com.ruoyi.system.domain.StandardScript;
import com.ruoyi.system.service.IStandardScriptService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 标准话术Controller
 *
 * @author ruoyi
 * @date 2025-02-25
 */
@RestController
@RequestMapping("/persona/script")
public class StandardScriptController extends BaseController {
    @Autowired
    private IStandardScriptService standardScriptService;

    /**
     * 查询标准话术列表
     */
    @PreAuthorize("@ss.hasPermi('persona:script:list')")
    @GetMapping("/list")
    public TableDataInfo list(StandardScript standardScript) {
        startPage();
        List<StandardScript> list = standardScriptService.selectStandardScriptList(standardScript);
        return getDataTable(list);
    }

    /**
     * 导出标准话术列表
     */
    @PreAuthorize("@ss.hasPermi('persona:script:export')")
    @Log(title = "标准话术", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StandardScript standardScript) {
        List<StandardScript> list = standardScriptService.selectStandardScriptList(standardScript);
        ExcelUtil<StandardScript> util = new ExcelUtil<StandardScript>(StandardScript.class);
        util.exportExcel(response, list, "标准话术数据");
    }

    /**
     * 获取标准话术详细信息
     */
    @PreAuthorize("@ss.hasPermi('persona:script:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(standardScriptService.selectStandardScriptById(id));
    }

    /**
     * 新增标准话术
     */
    @PreAuthorize("@ss.hasPermi('persona:script:add')")
    @Log(title = "标准话术", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StandardScript standardScript) {
        return toAjax(standardScriptService.insertStandardScript(standardScript));
    }

    /**
     * 修改标准话术
     */
    @PreAuthorize("@ss.hasPermi('persona:script:edit')")
    @Log(title = "标准话术", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StandardScript standardScript) {
        return toAjax(standardScriptService.updateStandardScript(standardScript));
    }

    /**
     * 删除标准话术
     */
    @PreAuthorize("@ss.hasPermi('persona:script:remove')")
    @Log(title = "标准话术", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(standardScriptService.deleteStandardScriptByIds(ids));
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil<StandardScript> util = new ExcelUtil<StandardScript>(StandardScript.class);
        util.importTemplateExcel(response, "标准话术");
    }

    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('persona:script:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<StandardScript> util = new ExcelUtil<StandardScript>(StandardScript.class);
        List<StandardScript> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = standardScriptService.importUser(userList, updateSupport, operName);
        return success(message);
    }


}
